<?php

// **************************************************************
// | Name: 星空框架 财务统计管理
// **************************************************************
// | Version: V5.0
// **************************************************************
// | Author: xkyinzhe <zhonghuaxinxing@sina.cn>
// **************************************************************
// | City: 青岛
// **************************************************************
// | Time: 2021-10-09 09:06
// **************************************************************
declare(strict_types=1);

namespace app\xingkong\controller\v1;

use app\common\common\BackendController;
use app\common\model\Finance as FinanceModel;
use app\common\model\StoreFinance as StoreFinanceModel;
use app\common\model\SecondFinance as SecondFinanceModel;
use app\common\model\ExpertFinance as ExpertFinanceModel;
use app\common\model\Withdrawal as WithDrawalModel;
use app\common\model\SecondWithdrawal as SecondWithdrawalModel;
use app\common\model\StoreWihtdrawal as StoreWihtdrawalModel;
use app\common\model\User as UserModel;
use app\common\model\BackMoney as BackMoneyModel;
use app\common\model\MoneyChanage as MoneyChanageModel;
use app\common\model\UserAchievement as UserAchievementModel;
use app\common\controller\Huigongbao;
use app\common\services\UserServices;
use think\facade\Db;
use think\facade\View;

/**
 * @xk 财务统计
 */
class Finance extends BackendController
{
    // ****************
    // | 流水记录
    // *******************
    /**
     * @xk 流水记录
     *
     * @method finance
     * @param  FinanceModel $financeModel              [description]
     * @return [type]       [description]
     * @Time   2021-10-09
     * @City   青岛
     * @Author xkyinzhe     <zhonghuaxinxing@sina.cn>
     */
    public function finance(FinanceModel $financeModel)
    {
        $param = request()->param();
        if (request()->isAjax()) {
            $page = isset($param['page']) ? (int)$param['page'] : 1;
            $limit = isset($param['limit']) ? (int)$param['limit'] : 30;
            $keywords = isset($param['keywords']) ? $param['keywords'] : '';
            $search_time = isset($param['search_time']) ? $param['search_time'] : '';
            $act = isset($param['act']) ? $param['act'] : '';
            $entry = isset($param['entry']) ? $param['entry'] : '';
            $pay_type = isset($param['pay_type']) ? $param['pay_type'] : '';
            $condition = [];
            if ($keywords != '') {
                $condition[] = ['f.finance_sn|f.pay_order_sn|f.relation_num|f.relation_user_num|u.user_name','like','%'.$keywords.'%'];
            }
            if ($search_time) {
                $search_time_arr = explode('~', $search_time);
                $start_time = $search_time_arr[0];
                $end_time = $search_time_arr[1];
                $condition[] = ['f.create_time', 'between time', $start_time.','.$end_time];
            }
            // if ($act != '') {
            //     $condition[] = ['f.act','in',$act];
            // }
            $condition[] = ['f.act','<>',3]; // 去除提现记录
            if ($entry != '') {
                $condition[] = ['f.entry','in',$entry];
            }
            if ($pay_type != '') {
                $condition[] = ['f.pay_type','in',$pay_type];
            }
            $resultData = [];
            $resultData['list'] = $financeModel
                            ->alias('f')
                            ->leftJoin('user u', 'u.user_sn = f.relation_user_num')
                            ->field('f.*,u.`user_name`')
                            ->where($condition)
                            ->withAttr('pay_type', function ($value, $data) {
                                return getPayTypeText($value);
                            })
                            ->withAttr('act', function ($value, $data) {
                                return getFinanceAct($value);
                            })
                            ->withAttr('entry', function ($value, $data) {
                                return getFinanceEntry($value);
                            })
                            ->withAttr('money', function ($value, $data) {
                                return $data['entry']==1 ? '<span style="color:red;">+'.$value.'</span>' : '<span style="color:green;">-'.$value.'</span>';
                            })
                            ->page($page, $limit)
                            ->order('create_time desc')
                            ->select()
                            ->toArray();
            $resultData['count'] = $financeModel
                                  ->alias('f')
                                  ->leftJoin('user u', 'u.user_sn = f.relation_user_num')
                                  ->where($condition)
                                  ->count();
            $all_price = $financeModel->alias('f')->leftJoin('user u', 'u.user_sn = f.relation_user_num')->where($condition)->where([['f.entry','=',1]])->sum('money');
            $all_push = $financeModel->alias('f')->leftJoin('user u', 'u.user_sn = f.relation_user_num')->where($condition)->where([['f.entry','=',2]])->sum('money');
            $all_in_count = $financeModel->alias('f')->leftJoin('user u', 'u.user_sn = f.relation_user_num')->where($condition)->where([['f.entry','=',1]])->count();
            $all_count = $financeModel->alias('f')->leftJoin('user u', 'u.user_sn = f.relation_user_num')->where($condition)->where([['f.entry','=',2]])->count();
            $resultData['show_count'] = '总收入：'.$all_price.'元;  总支出：'.$all_push.'元 总入账笔数：'.$all_in_count.'笔 总出账笔数：'.$all_count.'笔';
            $this->result(200, '请求成功', 200, '加载成功', $resultData);
        }
        return View::fetch();
    }
    /**
     * @xk 导出流水记录
     *
     * @method exportFinance
     * @param  FinanceModel  $financeModel              [description]
     * @return [type]        [description]
     * @Time   2021-10-09
     * @City   青岛
     * @Author xkyinzhe      <zhonghuaxinxing@sina.cn>
     */
    public function exportFinance(FinanceModel $financeModel)
    {
        $param = request()->param();
        $keywords = isset($param['keywords']) ? $param['keywords'] : '';
        $search_time = isset($param['search_time']) ? $param['search_time'] : '';
        $act = isset($param['act']) ? $param['act'] : '';
        $entry = isset($param['entry']) ? $param['entry'] : '';
        $pay_type = isset($param['pay_type']) ? $param['pay_type'] : '';
        $condition = [];
        if ($keywords) {
            $condition[] = ['f.finance_sn|f.pay_order_sn|f.relation_num|f.relation_user_num|u.user_name','like','%'.$keywords.'%'];
        }
        if ($search_time) {
            $search_time_arr = explode('~', $search_time);
            $start_time = $search_time_arr[0];
            $end_time = $search_time_arr[1];
            // $start_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[0]).' 00:00:00')); //当前时间0点开始
            // $end_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[1]).' 23:59:59')); //当前时间0点开始
            $condition[] = ['f.create_time', 'between time', $start_time.','.$end_time];
        }
        if ($act != '') {
            $condition[] = ['f.act','in',$act];
        }
        if ($entry != '') {
            $condition[] = ['f.entry','in',$entry];
        }
        if ($pay_type != '') {
            $condition[] = ['f.pay_type','in',$pay_type];
        }
        $allCount = $financeModel
                    ->alias('f')
                    ->leftJoin('user u', 'u.user_sn = f.relation_user_num')
                    ->where($condition)
                    ->count(); // 总数居
        $limit = 10000;
        $pages = ceil($allCount / $limit);
        $url_arr = [];
        for ($i = 1; $i <= $pages; ++$i) {
            $data = $financeModel
                    ->alias('f')
                    ->leftJoin('user u', 'u.user_sn = f.relation_user_num')
                    ->field('f.*,u.`user_name`')
                    ->where($condition)
                    ->withAttr('pay_type', function ($value, $data) {
                        return getPayTypeText($value);
                    })
                    ->withAttr('act', function ($value, $data) {
                        return getFinanceAct($value);
                    })
                    ->withAttr('entry', function ($value, $data) {
                        return getFinanceEntry($value);
                    })
                    ->withAttr('money', function ($value, $data) {
                        return $data['entry']==1 ? '+'.$value : '-'.$value.'';
                    })
                    ->page($i, $limit)
                    ->order('create_time desc')
                    ->select()
                    ->toArray();
            if ($data) {
                $order_data = [];
                foreach ($data as $key => $value) {
                    $arrays = [];
                    if ($value) {
                        $arrays[] = $value['finance_id'];
                        $arrays[] = $value['user_name'];
                        $arrays[] = $value['relation_user_num'];
                        $arrays[] = $value['relation_num'];
                        $arrays[] = $value['pay_order_sn'];
                        $arrays[] = $value['money'];
                        $arrays[] = $value['act'];
                        $arrays[] = $value['entry'];
                        $arrays[] = $value['content'];
                        $arrays[] = $value['create_time'];
                    }
                    $order_data[] = $arrays;
                }
                $title = ['流水ID','昵称','用户编号','关联单号','支付流水号','变动金额','支付类型','变动类型','变动备注','变动时间'];
                $width = [25,25,15,15,30,15,15,40,25];
                $path = '/export/finance';
                $result = $financeModel->export($title, $order_data, $path, $width, $i, '流水记录表');
                $url_arr[] = $result;
            }
        }
        $code = 200;
        $msg = '请求成功';
        $result_code = 200;
        $result_msg = '导出成功';
        $resultData = $url_arr;
        $this->result($code, $msg, $result_code, $result_msg, $resultData);
    }
    // ***************
    // | 广告佣金
    // ************************
    /**
     * @xk 广告佣金列表
     *
     * @method agencyMoneyLog
     * @param  BackMoneyModel $backMoneyModel            [description]
     * @return [type]         [description]
     * @Time   2021-11-09
     * @City   青岛
     * @Author xkyinzhe       <zhonghuaxinxing@sina.cn>
     */
    public function agencyMoneyLog(BackMoneyModel $backMoneyModel)
    {
        $param = request()->param();
        if (request()->isAjax()) {
            $page = isset($param['page']) ? (int)$param['page'] : 1;
            $limit = isset($param['limit']) ? (int)$param['limit'] : 30;
            $keywords = isset($param['keywords']) ? $param['keywords'] : '';
            $is_finance = isset($param['is_finance']) ? $param['is_finance'] : '';
            $search_time = isset($param['search_time']) ? $param['search_time'] : '';
            $finance_time = isset($param['finance_time']) ? $param['finance_time'] : '';
            $condition = [];
            if ($keywords != '') {
                $condition[] = ['u.user_sn|u.user_name|u.tel|bc.sub_order_sn','like','%'.$keywords.'%'];
            }
            if ($search_time != '') {
                $search_time_arr = explode('~', $search_time);
                $start_time = $search_time_arr[0];
                $end_time = $search_time_arr[1];
                $condition[] = ['bc.create_time', 'between time', $start_time.','.$end_time];
            }
            if ($finance_time != '') {
                $search_time_arr = explode('~', $finance_time);
                $start_time = $search_time_arr[0];
                $end_time = $search_time_arr[1];
                $condition[] = ['bc.finance_time', 'between time', $start_time.','.$end_time];
            }
            if($is_finance != ''){
              $condition[] = ['bc.is_finance','in',$is_finance];
            }
            $condition[] = ['act','in','1,11']; // 代理佣金
            $resultData = [];
            $resultData['list'] = $backMoneyModel
                            ->alias('bc')
                            ->leftJoin('user u', 'u.user_sn=bc.user_sn')
                            ->where($condition)
                            ->field('u.`user_name`,u.`user_sn`,bc.`sub_order_sn`,bc.`money`,bc.`content`,bc.`create_time`,u.`user_name` as type,bc.`achievement_price`,bc.`is_finance` as finance_txt,bc.`act`,bc.`finance_time`')
                            ->withAttr('type', function ($value, $data) {
                                return  '广告佣金';
                            })
                            ->withAttr('achievement_price', function ($value, $data) {
                                return $data['act'] == 1 ? '<span style="color:green;">'.$value.'</span>' : '<span style="color:red;">-'.$value.'</span>';
                            })
                            ->withAttr('money', function ($value, $data) {
                                return $data['act'] == 1 ? '<span style="color:green;">'.$value.'</span>' : '<span style="color:red;">-'.$value.'</span>';
                            })
                            ->withAttr('finance_txt', function ($value, $data) {
                                return $value==0 ? '<span>未出账</span>' : ($value==1 ? '<span style="color:green">出账成功</span>' : '<span style="color:red">出账失败</span>');
                            })
                            ->page($page, $limit)
                            ->order('bc.create_time desc')
                            ->select()
                            ->toArray();
            $resultData['count'] = $backMoneyModel
                             ->alias('bc')
                             ->leftJoin('user u', 'u.user_sn=bc.user_sn')
                             ->where($condition)
                             ->count();
            $all_price = $backMoneyModel
                        ->alias('bc')
                        ->leftJoin('user u', 'u.user_sn=bc.user_sn')
                        ->where($condition)
                        ->where([['bc.act','=',1],['bc.is_finance','=',1]])
                        ->sum('money');
            $entry_price = $backMoneyModel
                        ->alias('bc')
                        ->leftJoin('user u', 'u.user_sn=bc.user_sn')
                        ->where($condition)
                        ->where([['bc.act','=',11],['bc.is_finance','=',1]])
                        ->sum('money');
            $all_wait_price = $backMoneyModel
                        ->alias('bc')
                        ->leftJoin('user u', 'u.user_sn=bc.user_sn')
                        ->where($condition)
                        ->where([['bc.act','=',1],['bc.is_finance','=',0]])
                        ->sum('money');
            $entry_wait_price = $backMoneyModel
                        ->alias('bc')
                        ->leftJoin('user u', 'u.user_sn=bc.user_sn')
                        ->where($condition)
                        ->where([['bc.act','=',11],['bc.is_finance','=',0]])
                        ->sum('money');
            $resultData['show_count'] = '总计：已出账：'.($all_price-$entry_price).'元；未出账：'.($all_wait_price-$entry_wait_price).'元';
            $this->result(200, '请求成功', 200, '加载成功', $resultData);
        }
        return View::fetch();
    }
    /**
     * @xk 广告佣金导出
     *
     * @method exportAgencyMoneyLog
     * @param  UserModel            $userModel                 [description]
     * @param  BackMoneyModel       $backMoneyModel            [description]
     * @return [type]               [description]
     * @Time   2021-11-10
     * @City   青岛
     * @Author xkyinzhe             <zhonghuaxinxing@sina.cn>
     */
    public function exportAgencyMoneyLog(BackMoneyModel $backMoneyModel)
    {
        $param = request()->param();
        $keywords = isset($param['keywords']) ? $param['keywords'] : '';
        $is_finance = isset($param['is_finance']) ? $param['is_finance'] : '';
        $search_time = isset($param['search_time']) ? $param['search_time'] : '';
        $finance_time = isset($param['finance_time']) ? $param['finance_time'] : '';
        $condition = [];
        if ($keywords != '') {
            $condition[] = ['u.user_sn|u.user_name|u.tel|bc.sub_order_sn','like','%'.$keywords.'%'];
        }
        if ($search_time != '') {
            $search_time_arr = explode('~', $search_time);
            $start_time = $search_time_arr[0];
            $end_time = $search_time_arr[1];
            $condition[] = ['bc.create_time', 'between time', $start_time.','.$end_time];
        }
        if ($finance_time != '') {
            $search_time_arr = explode('~', $finance_time);
            $start_time = $search_time_arr[0];
            $end_time = $search_time_arr[1];
            $condition[] = ['bc.finance_time', 'between time', $start_time.','.$end_time];
        }
        if($is_finance != ''){
          $condition[] = ['bc.is_finance','in',$is_finance];
        }
        $condition[] = ['act','in','1,11']; // 代理佣金
        $allCount = $backMoneyModel
                       ->alias('bc')
                       ->leftJoin('user u', 'u.user_sn=bc.user_sn')
                       ->where($condition)
                       ->count();
        $limit = 10000;
        $pages = ceil($allCount / $limit);
        for ($i = 1; $i <= $pages; ++$i) {
            $data = $backMoneyModel
                  ->alias('bc')
                  ->leftJoin('user u', 'u.user_sn=bc.user_sn')
                  ->where($condition)
                  ->field('u.`user_name`,u.`user_sn`,bc.`sub_order_sn`,bc.`money`,bc.`content`,bc.`create_time`,u.`user_name` as type,bc.`achievement_price`,bc.`is_finance` as finance_txt,bc.`act`,bc.`finance_time`')
                  ->withAttr('type', function ($value, $data) {
                      return  '佣金';
                  })
                  ->withAttr('achievement_price', function ($value, $data) {
                      return $data['act'] == 1 ? $value : '-'.$value;
                  })
                  ->withAttr('money', function ($value, $data) {
                      return $data['act'] == 1 ? $value : '-'.$value;
                  })
                  ->withAttr('finance_txt', function ($value, $data) {
                      return $value==0 ? '未出账' : ($value==1 ? '出账成功' : '出账失败');
                  })
                  ->page($i, $limit)
                  ->order('bc.create_time desc')
                  ->select()
                  ->toArray();
            if ($data) {
                $order_data = [];
                foreach ($data as $key => $value) {
                    $arrays = [];
                    if ($value) {
                        $arrays[] = $value['user_name'];
                        $arrays[] = $value['user_sn'];
                        $arrays[] = $value['sub_order_sn'];
                        $arrays[] = $value['type'];
                        $arrays[] = $value['money'];
                        $arrays[] = $value['achievement_price'];
                        $arrays[] = $value['finance_txt'];
                        $arrays[] = $value['content'];
                        $arrays[] = $value['create_time'];
                        $arrays[] = $value['finance_time'];
                    }
                    $order_data[] = $arrays;
                }
                $title = ['昵称','用户编号','关联单号','类型','金额','业绩金额','是否出账','备注','创建时间','出账时间'];
                $width = [25,25,15,15,15,15,15,60,25,25];
                $path = '/export/agency';
                $result = $backMoneyModel->export($title, $order_data, $path, $width, $i, '广告佣金表');
                $url_arr[] = $result;
            }
        }
        $code = 200;
        $msg = '请求成功';
        $result_code = 200;
        $result_msg = '导出成功';
        $resultData = $url_arr;
        $this->result($code, $msg, $result_code, $result_msg, $resultData);
    }
    // **************
    // | 代理佣金
    // ******************
    /**
     * @xk 代理佣金
     *
     * @method agentMoneyLog
     * @param  UserModel      $userModel                 [description]
     * @param  BackMoneyModel $backMoneyModel            [description]
     * @return [type]         [description]
     * @Time   2021-11-10
     * @City   青岛
     * @Author xkyinzhe       <zhonghuaxinxing@sina.cn>
     */
    public function agentMoneyLog(BackMoneyModel $backMoneyModel)
    {
        $param = request()->param();
        $user_sn = isset($param['user_sn']) ? $param['user_sn'] : '';
        if (request()->isAjax()) {
            $page = isset($param['page']) ? (int)$param['page'] : 1;
            $limit = isset($param['limit']) ? (int)$param['limit'] : 30;
            $keywords = isset($param['keywords']) ? $param['keywords'] : '';
            $is_finance = isset($param['is_finance']) ? $param['is_finance'] : '';
            $create_time = isset($param['create_time']) ? $param['create_time'] : '';
            $finance_time = isset($param['finance_time']) ? $param['finance_time'] : '';
            $act = isset($param['act']) ? ($param['act'] ? $param['act'] : '2,3') : '2,3';
            $user_level = isset($param['user_level'])?$param['user_level']:'';
            $condition = [];
            if ($keywords != '') {
                $condition[] = ['bc.user_sn|bc.sub_order_sn','like','%'.$keywords.'%'];
            }
            if ($is_finance != '') {
                $condition[] = ['bc.is_finance','in',$is_finance];
            }
            if ($create_time != '') {
                $search_time_arr = explode('~', $create_time);
                $start_time = $search_time_arr[0];
                $end_time = $search_time_arr[1];
                $condition[] = ['bc.create_time', 'between time', $start_time.','.$end_time];
            }
            if ($finance_time != '') {
                $search_time_arr = explode('~', $finance_time);
                $start_time = $search_time_arr[0];
                $end_time = $search_time_arr[1];
                $condition[] = ['bc.finance_time', 'between time', $start_time.','.$end_time];
            }
            // echo $act; die();
            if ($act != '') {
                $condition[] = ['act','in',$act];
            }
            if($user_level != ''){
              $condition[] = ['bc.user_level','in',$user_level];
            }
            $condition[] = ['money','>',0];
            $resultData = [];
            $resultData['list'] = $backMoneyModel
                              ->alias('bc')
                              ->leftJoin('user u', 'u.user_sn=bc.user_sn')
                              ->leftJoin('userLevel ul', 'ul.level = bc.user_level')
                              ->where($condition)
                              ->field('bc.`back_money_id`,bc.`act`,u.`user_name`,u.`user_sn`,bc.`money`,ul.`level_name`,bc.`achievement_price`,bc.`agent_bili`,bc.`level_bili`,bc.`sub_order_sn`,bc.`is_finance`,bc.`is_finance` as finance_txt,bc.`create_time`,bc.`finance_time`')
                              ->withAttr('finance_txt', function ($value, $data) {
                                  return $value==0 ? '<span>未出账</span>' : ($value==1 ? '<span style="color:green">出账成功</span>' : '<span style="color:red">出账失败</span>');
                              })
                              ->withAttr('act', function ($value, $data) {
                                  return getBonusType($value);
                              })
                              ->page($page, $limit)
                              ->order('bc.create_time desc')
                              ->select()
                              ->toArray();
            $resultData['count'] = $backMoneyModel
                               ->alias('bc')
                               ->where($condition)
                               ->count();
            $all_push = $backMoneyModel
                               ->alias('bc')
                               ->where($condition)
                               ->where([['bc.is_finance','=',1]])
                               ->sum('money');
            $all_price = $backMoneyModel
                                ->alias('bc')
                                ->where($condition)
                                ->where([['bc.is_finance','=',0]])
                                ->sum('money');
            $resultData['show_count'] = '全部已出帐：'.$all_push.'元;  全部未出账：'.$all_price.'元；';
            $this->result(200, '请求成功', 200, '加载成功', $resultData);
        }
        return View::fetch('', ['user_sn'=>$user_sn]);
    }
    /**
     * @xk 代理佣金出账
     *
     * @method doAgentFinance
     * @param  BackMoneyModel $backMoneyModel            [description]
     * @param  UserServices   $userServices              [description]
     * @return [type]         [description]
     * @Time   2021-11-11
     * @City   青岛
     * @Author xkyinzhe       <zhonghuaxinxing@sina.cn>
     */
    public function doAgentFinance(BackMoneyModel $backMoneyModel, UserServices $userServices)
    {
        Db::startTrans();
        $code = 200;
        $msg = '请求成功';
        try {
            $param = request()->param();
            $act = isset($param['act']) ? $param['act'] : 'one';
            switch ($act) {
              case 'all':
                // 全部出账  代理佣金和平级佣金
                $back_money_ids = $backMoneyModel->where([['is_finance','=',0],['act','in','2,3']])->column('back_money_id');
                $userServices->syncPushBackMoney($back_money_ids);
              break;
              case 'choose':
                $back_money_ids = isset($param['back_money_ids']) ? $param['back_money_ids'] : '';
                if (!$back_money_ids || $back_money_ids == '') {
                    throw new \think\Exception("请选择需要出账的数据", 1);
                }
                $userServices->syncPushBackMoney($back_money_ids);
              break;
              default:
                // 单个出账
                $back_money_id = isset($param['back_money_id']) ? $param['back_money_id'] : 0; // 账单id
                $userServices->syncPushBackMoney($back_money_id); // 执行账单出账
              break;
            }
            Db::commit();
            $result_code = 200;
            $result_msg = '加载成功';
        } catch (\Exception $e) {
            Db::rollback();
            $result_code = 404;
            $result_msg = $e->getMessage();
        }
        $this->result($code, $msg, $result_code, $result_msg);
    }
    /**
     * @xk 代理佣金导出
     *
     * @method exportAgentMoneyLog
     * @param  UserModel           $userModel                 [description]
     * @param  BackMoneyModel      $backMoneyModel            [description]
     * @return [type]              [description]
     * @Time   2021-11-10
     * @City   青岛
     * @Author xkyinzhe            <zhonghuaxinxing@sina.cn>
     */
    public function exportAgentMoneyLog(UserModel $userModel, BackMoneyModel $backMoneyModel)
    {
        $param = request()->param();
        $keywords = isset($param['keywords']) ? $param['keywords'] : '';
        $is_finance = isset($param['is_finance']) ? $param['is_finance'] : '';
        $create_time = isset($param['create_time']) ? $param['create_time'] : '';
        $finance_time = isset($param['finance_time']) ? $param['finance_time'] : '';
        $act = isset($param['act']) ? ($param['act'] ? $param['act'] : '2,3') : '2,3';
        $condition = [];
        if ($keywords != '') {
            $condition[] = ['bc.user_sn|bc.sub_order_sn','like','%'.$keywords.'%'];
        }
        if ($is_finance != '') {
            $condition[] = ['bc.is_finance','in',$is_finance];
        }
        if ($create_time != '') {
            $search_time_arr = explode('~', $create_time);
            $start_time = $search_time_arr[0];
            $end_time = $search_time_arr[1];
            $condition[] = ['bc.create_time', 'between time', $start_time.','.$end_time];
        }
        if ($finance_time != '') {
            $search_time_arr = explode('~', $finance_time);
            $start_time = $search_time_arr[0];
            $end_time = $search_time_arr[1];
            $condition[] = ['bc.finance_time', 'between time', $start_time.','.$end_time];
        }
        if ($act != '') {
            $condition[] = ['act','in',$act];
        }
        $allCount = $backMoneyModel
                     ->alias('bc')
                     ->where($condition)
                     ->count();
        $limit = 10000;
        $pages = ceil($allCount / $limit);
        for ($i = 1; $i <= $pages; ++$i) {
            $data = $backMoneyModel
                ->alias('bc')
                ->leftJoin('user u', 'u.user_sn=bc.user_sn')
                ->leftJoin('userLevel ul', 'ul.level = bc.user_level')
                ->where($condition)
                ->field('u.`user_name`,u.`user_sn`,bc.`act`,bc.`money`,ul.`level_name`,bc.`agent_bili`,bc.`level_bili`,bc.`sub_order_sn`,bc.`is_finance`,bc.`content`,bc.`create_time`,bc.`finance_time`')
                ->withAttr('is_finance', function ($value, $data) {
                    return $value==0 ? '未出账' : ($value==1 ? '出账成功' : '出账失败');
                })
                ->withAttr('act', function ($value, $data) {
                    return getBonusType($value);
                })
                ->page($i, $limit)
                ->order('bc.create_time desc')
                ->select()
                ->toArray();
            if ($data) {
                $order_data = [];
                foreach ($data as $key => $value) {
                    $arrays = [];
                    if ($value) {
                        $arrays[] = $value['user_name'];
                        $arrays[] = $value['user_sn'];
                        $arrays[] = $value['money'];
                        $arrays[] = $value['act'];
                        $arrays[] = $value['level_name'];
                        $arrays[] = $value['agent_bili'];
                        $arrays[] = $value['level_bili'];
                        $arrays[] = $value['sub_order_sn'];
                        $arrays[] = $value['is_finance'];
                        $arrays[] = $value['create_time'];
                        $arrays[] = $value['finance_time'];
                    }
                    $order_data[] = $arrays;
                }
                $title = ['昵称','用户编号','出账金额','出账类型','代理等级','佣金比例','平级奖比例','关联订单编号','是否出账','创建时间','出账时间'];
                $width = [25,25,20,20,20,20,20,20,25,25];
                $path = '/export/agent';
                $result = $backMoneyModel->export($title, $order_data, $path, $width, $i, '代理佣金表');
                $url_arr[] = $result;
            }
        }
        $code = 200;
        $msg = '请求成功';
        $result_code = 200;
        $result_msg = '导出成功';
        $resultData = $url_arr;
        $this->result($code, $msg, $result_code, $result_msg, $resultData);
    }
    // *****************
    // | 代理佣金汇总
    // ******************
    /**
     * @xk 代理佣金汇总
     * @method          agentAllList
     * @param           BackMoneyModel $backMoneyModel  [description]
     * @return          [type] [description]
     * @Version：V5.0
     * @Author：xkyinzhe <zhonghuaxinxing@sina.cn>
     * @City：           青岛
     * @Time：2022-04-19
     */
    public function agentAllList(BackMoneyModel $backMoneyModel, UserModel $userModel)
    {
        $param = request()->param();
        if (request()->isAjax()) {
            $page = isset($param['page']) ? (int)$param['page'] : 1;
            $limit = isset($param['limit']) ? (int)$param['limit'] : 30;
            $keywords = isset($param['keywords']) ? $param['keywords'] : '';
            $is_finance = isset($param['is_finance']) ? $param['is_finance'] : '';
            $create_time = isset($param['create_time']) ? $param['create_time'] : '';
            $finance_time = isset($param['finance_time']) ? $param['finance_time'] : '';
            $act = isset($param['act']) ? ($param['act'] ? $param['act'] : '2,3') : '2,3';
            $condition = [];
            if ($keywords != '') {
                $condition[] = ['bc.user_sn|bc.sub_order_sn','like','%'.$keywords.'%'];
            }
            if ($is_finance != '') {
                $condition[] = ['bc.is_finance','in',$is_finance];
            }
            if ($create_time != '') {
                $search_time_arr = explode('~', $create_time);
                $start_time = $search_time_arr[0];
                $end_time = $search_time_arr[1];
                $condition[] = ['bc.create_time', 'between time', $start_time.','.$end_time];
            }
            if ($finance_time != '') {
                $search_time_arr = explode('~', $finance_time);
                $start_time = $search_time_arr[0];
                $end_time = $search_time_arr[1];
                $condition[] = ['bc.finance_time', 'between time', $start_time.','.$end_time];
            }
            if ($act != '') {
                $condition[] = ['bc.act','in',$act];
            } else {
                $condition[] = ['bc.act','in','2,3'];
            }
            $list= $backMoneyModel
                    ->alias('bc')
                    ->leftJoin('user u', 'u.user_sn=bc.user_sn')
                    ->where($condition)
                    ->field('bc.`user_sn`,sum(bc.`money`) as `all_back_money`,u.`user_name`')
                    ->page($page, $limit)
                    ->group('bc.user_sn')
                    ->select()
                    ->toArray();
            if ($list) {
                foreach ($list as $key => $value) {
                    $user_info = $userModel
                              ->alias('u')
                              ->leftJoin('userLevel ul', 'ul.level=u.level')
                              ->where([['u.user_sn','=',$value['user_sn']]])
                              ->field('ul.level_name')
                              ->find();
                    $user_info = $user_info ? $user_info->toArray() : [];
                    $user_level = $user_info['level_name'];
                    $list[$key]['user_level'] = $user_level;
                }
            }
            $resultData['list'] = $list;
            $resultData['count'] = $backMoneyModel
                               ->alias('bc')
                               ->where($condition)
                               ->group('bc.user_sn')
                               ->count();
            // $resultData['show_count'] = '全部已出帐：'.$all_push.'元;  全部未出账：'.$all_price.'元；';
            $this->result(200, '请求成功', 200, '加载成功', $resultData);
        }
        return View::fetch();
    }
    /**
     * @xk 导出佣金汇总表
     * @method          exportAgentAll
     * @param           UserModel $userModel  [description]
     * @param           BackMoneyModel $backMoneyModel  [description]
     * @return          [type] [description]
     * @Version：V5.0
     * @Author：xkyinzhe <zhonghuaxinxing@sina.cn>
     * @City：           青岛
     * @Time：2022-05-11
     */
    public function exportAgentAll(UserModel $userModel, BackMoneyModel $backMoneyModel)
    {
        $param = request()->param();
        $keywords = isset($param['keywords']) ? $param['keywords'] : '';
        $is_finance = isset($param['is_finance']) ? $param['is_finance'] : '';
        $create_time = isset($param['create_time']) ? $param['create_time'] : '';
        $finance_time = isset($param['finance_time']) ? $param['finance_time'] : '';
        $act = isset($param['act']) ? ($param['act'] ? $param['act'] : '2,3') : '2,3';
        $condition = [];
        if ($keywords != '') {
            $condition[] = ['bc.user_sn|bc.sub_order_sn','like','%'.$keywords.'%'];
        }
        if ($is_finance != '') {
            $condition[] = ['bc.is_finance','in',$is_finance];
        }
        if ($create_time != '') {
            $search_time_arr = explode('~', $create_time);
            $start_time = $search_time_arr[0];
            $end_time = $search_time_arr[1];
            $condition[] = ['bc.create_time', 'between time', $start_time.','.$end_time];
        }
        if ($finance_time != '') {
            $search_time_arr = explode('~', $finance_time);
            $start_time = $search_time_arr[0];
            $end_time = $search_time_arr[1];
            $condition[] = ['bc.finance_time', 'between time', $start_time.','.$end_time];
        }
        if ($act != '') {
            $condition[] = ['bc.act','in',$act];
        } else {
            $condition[] = ['bc.act','in','2,3'];
        }
        $allCount = $backMoneyModel
                     ->alias('bc')
                     ->where($condition)
                     ->count();
        $limit = 10000;
        $pages = ceil($allCount / $limit);
        for ($i = 1; $i <= $pages; ++$i) {
            $data = $backMoneyModel
                    ->alias('bc')
                    ->leftJoin('user u', 'u.user_sn=bc.user_sn')
                    ->where($condition)
                    ->field('bc.`user_sn`,sum(bc.`money`) as `all_back_money`,u.`user_name`')
                    ->page($i, $limit)
                    ->group('bc.user_sn')
                    ->select()
                    ->toArray();
            if ($data) {
                $order_data = [];
                foreach ($data as $key => $value) {
                    $user_info = $userModel
                                ->alias('u')
                                ->leftJoin('userLevel ul', 'ul.level=u.level')
                                ->where([['u.user_sn','=',$value['user_sn']]])
                                ->field('ul.level_name')
                                ->find();
                    $arrays = [];
                    if ($value) {
                        $arrays[] = $value['user_name'];
                        $arrays[] = $value['user_sn'];
                        $arrays[] = $value['all_back_money'];
                        $arrays[] = $user_info['level_name'];
                    }
                    $order_data[] = $arrays;
                }
                $title = ['会员昵称','会员编号','出账总金额','代理等级'];
                $width = [25,25,20,20];
                $path = '/export/agentall';
                $result = $backMoneyModel->export($title, $order_data, $path, $width, $i, '代理佣金汇总表');
                $url_arr[] = $result;
            }
        }
        $code = 200;
        $msg = '请求成功';
        $result_code = 200;
        $result_msg = '导出成功';
        $resultData = $url_arr;
        $this->result($code, $msg, $result_code, $result_msg, $resultData);
    }
    // ****************
    // | 分红金额
    // ******************
    /**
     * @xk 分红金额
     * @method          bonusAllList
     * @param           BackMoneyModel $backMoneyModel  [description]
     * @return          [type] [description]
     * @Version：V5.0
     * @Author：xkyinzhe <zhonghuaxinxing@sina.cn>
     * @City：           青岛
     * @Time：2022-05-28
     */
    public function bonusAllList(BackMoneyModel $backMoneyModel,UserAchievementModel $userAchievementModel)
    {
        if (request()->isAjax()) {
            $condition = [];
            $condition[] = ['bc.act','=',4];
            $now_month = date('Y-m');
            $condition[] = ['bc.create_time','like',$now_month.'%'];
            $resultData = [];
            $list = $backMoneyModel
                              ->alias('bc')
                              ->leftJoin('bonusRule br', 'br.bonus_rule_id = bc.bonus_level')
                              ->where($condition)
                              ->field('bc.`back_money_id`,sum(bc.`money`) as all_money,bc.`bonus_level`,br.`bonus_name`,br.`bonus_bili`')
                              ->withAttr('bonus_bili',function($value,$data){
                                return ($value*100).'%';
                              })
                              ->order('bc.back_money_id desc')
                              ->group('bc.bonus_level')
                              ->select()
                              ->toArray();
            $all_condition = [];
            $now_month = getLastDate('Y-m', 2, 1);
            $all_condition[] = ['create_time','like',$now_month.'%'];
            $all_achievement_price = $userAchievementModel
                                ->where($all_condition)
                                ->group('sub_order_sn')
                                ->column('achievement_price');
            $all_achievement_price = array_sum($all_achievement_price);
            if ($list) {
                foreach ($list as $key => $value) {
                    $list[$key]['all_achievement_price'] = sprintf('%.2f',$all_achievement_price);
                }
            }
            $resultData['list'] = $list;
            $resultData['count'] = $backMoneyModel
                               ->alias('bc')
                               ->where($condition)
                               ->count();

            $all_bonus_money = $backMoneyModel
                           ->alias('bc')
                           ->where($condition)
                           ->sum('money');
            $resultData['show_count'] = '应分红总额：'.$all_bonus_money.'元;';

            $this->result(200, '请求成功', 200, '加载成功', $resultData);
        }
        return View::fetch();
    }
    // ******************
    // | 分红记录
    // ********************
    /**
     * @xk 分红记录列表
     * @method  bonusMoneyLog
     * @param   BackMoneyModel $backMoneyModel  [description]
     * @return  [type] [description]
     * @Version V5.0
     * @Time    2021-11-11
     * @City    青岛
     * @Author  xkyinzhe <zhonghuaxinxing@sina.cn>
     */
    public function bonusMoneyLog(BackMoneyModel $backMoneyModel)
    {
        $param = request()->param();
        if (request()->isAjax()) {
            $page = isset($param['page']) ? (int)$param['page'] : 1;
            $limit = isset($param['limit']) ? (int)$param['limit'] : 30;
            $keywords = isset($param['keywords']) ? $param['keywords'] : '';
            $is_finance = isset($param['is_finance']) ? $param['is_finance'] : '';
            $create_time = isset($param['create_time']) ? $param['create_time'] : '';
            $finance_time = isset($param['finance_time']) ? $param['finance_time'] : '';
            $condition = [];
            if ($keywords != '') {
                $condition[] = ['bc.user_sn|bc.sub_order_sn','like','%'.$keywords.'%'];
            }
            if ($is_finance != '') {
                $condition[] = ['bc.is_finance','in',$is_finance];
            }
            if ($create_time != '') {
                $search_time_arr = explode('~', $create_time);
                $start_time = $search_time_arr[0];
                $end_time = $search_time_arr[1];
                // $start_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[0]).' 00:00:00')); //当前时间0点开始
                // $end_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[1]).' 23:59:59')); //当前时间0点开始
                $condition[] = ['bc.create_time', 'between time', $start_time.','.$end_time];
            }
            if ($finance_time != '') {
                $search_time_arr = explode('~', $finance_time);
                $start_time = $search_time_arr[0];
                $end_time = $search_time_arr[1];
                // $start_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[0]).' 00:00:00')); //当前时间0点开始
                // $end_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[1]).' 23:59:59')); //当前时间0点开始
                $condition[] = ['bc.finance_time', 'between time', $start_time.','.$end_time];
            }
            $condition[] = ['act','=','4'];
            $resultData = [];
            $resultData['list'] = $backMoneyModel
                            ->alias('bc')
                            ->leftJoin('user u', 'u.user_sn=bc.user_sn')
                            ->where($condition)
                            ->field('bc.`back_money_id`,u.`user_name`,u.`user_sn`,bc.`money`,bc.`achievement_price`,bc.`bonus_level`,bc.`is_finance`,bc.`is_finance` as finance_txt,bc.`create_time`,bc.`finance_time`')
                            ->withAttr('finance_txt', function ($value, $data) {
                                return $value==0 ? '<span>未分红</span>' : ($value==1 ? '<span style="color:green">分红成功</span>' : '<span style="color:red">分红失败</span>');
                            })
                            ->order('bc.back_money_id desc')
                            ->page($page, $limit)
                            ->select()
                            ->toArray();
            $resultData['count'] = $backMoneyModel
                             ->alias('bc')
                             ->where($condition)
                             ->count();

            $all_push = $backMoneyModel
                        ->alias('bc')
                        ->where($condition)
                        ->where([['bc.is_finance','=',1]])
                        ->sum('money');
            $all_price = $backMoneyModel
                         ->alias('bc')
                         ->where($condition)
                         ->where([['bc.is_finance','=',0]])
                         ->sum('money');
            $resultData['show_count'] = '全部已分红：'.$all_push.'元;  全部未分红：'.$all_price.'元；';

            $this->result(200, '请求成功', 200, '加载成功', $resultData);
        }
        return View::fetch();
    }
    /**
     * @xk 分红出账
     * @method  doBonusFinance
     * @param   BackMoneyModel $backMoneyModel  [description]
     * @param   UserServices $userServices  [description]
     * @return  [type] [description]
     * @Version V5.0
     * @Time    2021-11-11
     * @City    青岛
     * @Author  xkyinzhe <zhonghuaxinxing@sina.cn>
     */
    public function doBonusFinance(BackMoneyModel $backMoneyModel, UserServices $userServices)
    {
        Db::startTrans();
        $code = 200;
        $msg = '请求成功';
        try {
            $param = request()->param();
            $act = isset($param['act']) ? $param['act'] : 'one';
            switch ($act) {
              case 'all':
                // 全部出账  代理佣金和平级佣金
                $back_money_ids = $backMoneyModel->where([['is_finance','=',0],['act','=','4']])->column('back_money_id');
                $userServices->syncPushBackMoney($back_money_ids);
                break;
              case 'choose':
                  $back_money_ids = isset($param['back_money_ids']) ? $param['back_money_ids'] : '';
                  if (!$back_money_ids || $back_money_ids == '') {
                      throw new \think\Exception("请选择需要分红的数据", 1);
                  }
                  $userServices->syncPushBackMoney($back_money_ids);
                  break;
              default:
                // 单个出账
                $back_money_id = isset($param['back_money_id']) ? $param['back_money_id'] : 0; // 账单id
                $userServices->syncPushBackMoney($back_money_id); // 执行账单出账
                break;
            }
            Db::commit();
            $result_code = 200;
            $result_msg = '加载成功';
        } catch (\Exception $e) {
            Db::rollback();
            $result_code = 404;
            $result_msg = $e->getMessage();
        }
        $this->result($code, $msg, $result_code, $result_msg);
    }
    /**
     * @xk 导出分红记录
     * @method  exportBonusMoneyLog
     * @param   BackMoneyModel $backMoneyModel  [description]
     * @return  [type] [description]
     * @Version V5.0
     * @Time    2021-11-11
     * @City    青岛
     * @Author  xkyinzhe <zhonghuaxinxing@sina.cn>
     */
    public function exportBonusMoneyLog(BackMoneyModel $backMoneyModel)
    {
        $param = request()->param();
        $keywords = isset($param['keywords']) ? $param['keywords'] : '';
        $is_finance = isset($param['is_finance']) ? $param['is_finance'] : '';
        $create_time = isset($param['create_time']) ? $param['create_time'] : '';
        $finance_time = isset($param['finance_time']) ? $param['finance_time'] : '';
        $condition = [];
        if ($keywords != '') {
            $condition[] = ['bc.user_sn|bc.sub_order_sn','like','%'.$keywords.'%'];
        }
        if ($is_finance != '') {
            $condition[] = ['bc.is_finance','in',$is_finance];
        }
        if ($create_time != '') {
            $search_time_arr = explode('~', $create_time);
            $start_time = $search_time_arr[0];
            $end_time = $search_time_arr[1];
            // $start_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[0]).' 00:00:00')); //当前时间0点开始
            // $end_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[1]).' 23:59:59')); //当前时间0点开始
            $condition[] = ['bc.create_time', 'between time', $start_time.','.$end_time];
        }
        if ($finance_time != '') {
            $search_time_arr = explode('~', $finance_time);
            $start_time = $search_time_arr[0];
            $end_time = $search_time_arr[1];
            // $start_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[0]).' 00:00:00')); //当前时间0点开始
            // $end_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[1]).' 23:59:59')); //当前时间0点开始
            $condition[] = ['bc.finance_time', 'between time', $start_time.','.$end_time];
        }
        $condition[] = ['act','=','4'];
        $allCount = $backMoneyModel
                   ->alias('bc')
                   ->where($condition)
                   ->count();
        $limit = 10000;
        $pages = ceil($allCount / $limit);
        for ($i = 1; $i <= $pages; ++$i) {
            $data = $backMoneyModel
              ->alias('bc')
              ->leftJoin('user u', 'u.user_sn=bc.user_sn')
              ->where($condition)
              ->field('bc.`back_money_id`,u.`user_name`,u.`user_sn`,bc.`money`,bc.`bonus_level`,bc.`is_finance`,bc.`create_time`,bc.`finance_time`')
              ->withAttr('is_finance', function ($value, $data) {
                  return $value==0 ? '未分红' : ($value==1 ? '分红成功' : '分红失败');
              })
              ->page($i, $limit)
              ->order('bc.create_time desc')
              ->select()
              ->toArray();
            if ($data) {
                $order_data = [];
                foreach ($data as $key => $value) {
                    $arrays = [];
                    if ($value) {
                        $arrays[] = $value['user_name'];
                        $arrays[] = $value['user_sn'];
                        $arrays[] = $value['money'];
                        $arrays[] = $value['bonus_level'];
                        $arrays[] = $value['is_finance'];
                        $arrays[] = $value['create_time'];
                        $arrays[] = $value['finance_time'];
                    }
                    $order_data[] = $arrays;
                }
                $title = ['昵称','用户编号','分红金额','分红等级','是否分红','创建时间','出账时间'];
                $width = [25,25,20,20,20,25,25];
                $path = '/export/bonus';
                $result = $backMoneyModel->export($title, $order_data, $path, $width, $i, '分红记录表');
                $url_arr[] = $result;
            }
        }
        $code = 200;
        $msg = '请求成功';
        $result_code = 200;
        $result_msg = '导出成功';
        $resultData = $url_arr;
        $this->result($code, $msg, $result_code, $result_msg, $resultData);
    }
    // *******************
    // | 其他收益
    // ************************
    /**
     * @xk 其他收益列表
     * @method  otherMoneyLog
     * @param   BackMoneyModel $backMoneyModel  [description]
     * @return  [type] [description]
     * @Version V5.0
     * @Time    2021-11-11
     * @City    青岛
     * @Author  xkyinzhe <zhonghuaxinxing@sina.cn>
     */
    public function otherMoneyLog(BackMoneyModel $backMoneyModel)
    {
        $param = request()->param();
        if (request()->isAjax()) {
            $page = isset($param['page']) ? (int)$param['page'] : 1;
            $limit = isset($param['limit']) ? (int)$param['limit'] : 30;
            $keywords = isset($param['keywords']) ? $param['keywords'] : '';
            $is_finance = isset($param['is_finance']) ? $param['is_finance'] : ''; // 是否结算
            $create_time = isset($param['create_time']) ? $param['create_time'] : '';
            $finance_time = isset($param['finance_time']) ? $param['finance_time'] : '';
            $condition = [];
            if ($keywords != '') {
                $condition[] = ['bc.user_sn|bc.sub_order_sn','like','%'.$keywords.'%'];
            }
            if ($is_finance != '') {
                $condition[] = ['bc.is_finance','in',$is_finance];
            }
            if ($create_time != '') {
                $search_time_arr = explode('~', $create_time);
                $start_time = $search_time_arr[0];
                $end_time = $search_time_arr[1];
                // $start_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[0]).' 00:00:00')); //当前时间0点开始
                // $end_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[1]).' 23:59:59')); //当前时间0点开始
                $condition[] = ['bc.create_time', 'between time', $start_time.','.$end_time];
            }
            if ($finance_time != '') {
                $search_time_arr = explode('~', $finance_time);
                $start_time = $search_time_arr[0];
                $end_time = $search_time_arr[1];
                // $start_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[0]).' 00:00:00')); //当前时间0点开始
                // $end_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[1]).' 23:59:59')); //当前时间0点开始
                $condition[] = ['bc.finance_time', 'between time', $start_time.','.$end_time];
            }
            $condition[] = ['act','=',10];
            $resultData = [];
            $resultData['list'] = $backMoneyModel
                            ->alias('bc')
                            ->leftJoin('user u', 'u.user_sn=bc.user_sn')
                            ->where($condition)
                            ->field('bc.`back_money_id`,u.`user_name`,u.`user_sn`,bc.`money`,bc.`content`,bc.`is_finance`,bc.`is_finance` as finance_txt,bc.`create_time`,bc.`finance_time`')
                            ->withAttr('finance_txt', function ($value, $data) {
                                return $value==0 ? '<span>未出账</span>' : ($value==1 ? '<span style="color:green">出账成功</span>' : '<span style="color:red">出账失败</span>');
                            })
                            ->order('bc.create_time desc')
                            ->page($page, $limit)
                            ->select()
                            ->toArray();
            $resultData['count'] = $backMoneyModel
                             ->alias('bc')
                             ->where($condition)
                             ->count();
            $all_push = $backMoneyModel
                       ->alias('bc')
                       ->where($condition)
                       ->where([['bc.is_finance','=',1]])
                       ->sum('money');
            $all_price = $backMoneyModel
                        ->alias('bc')
                        ->where($condition)
                        ->where([['bc.is_finance','=',0]])
                        ->sum('money');
            $resultData['show_count'] = '全部已出账：'.$all_push.'元;  全部未出账：'.$all_price.'元；';
            $this->result(200, '请求成功', 200, '加载成功', $resultData);
        }
        return View::fetch();
    }
    /**
     * @xk 其他收益出账
     * @method  doOtherMoneyFinance
     * @param   BackMoneyModel $backMoneyModel  [description]
     * @param   UserServices $userServices  [description]
     * @return  [type] [description]
     * @Version V5.0
     * @Time    2021-11-11
     * @City    青岛
     * @Author  xkyinzhe <zhonghuaxinxing@sina.cn>
     */
    public function doOtherMoneyFinance(BackMoneyModel $backMoneyModel, UserServices $userServices)
    {
        Db::startTrans();
        $code = 200;
        $msg = '请求成功';
        try {
            $param = request()->param();
            $act = isset($param['act']) ? $param['act'] : 'one';
            switch ($act) {
        case 'all':
          // 全部出账  代理佣金和平级佣金
          $back_money_ids = $backMoneyModel->where([['is_finance','=',0],['act','=','10']])->column('back_money_id');
          $userServices->syncPushBackMoney($back_money_ids);
          break;
        default:
          // 单个出账
          $back_money_id = isset($param['back_money_id']) ? $param['back_money_id'] : 0; // 账单id
          $userServices->syncPushBackMoney($back_money_id); // 执行账单出账
          break;
      }
            Db::commit();
            $result_code = 200;
            $result_msg = '加载成功';
        } catch (\Exception $e) {
            Db::rollback();
            $result_code = 404;
            $result_msg = $e->getMessage();
        }
        $this->result($code, $msg, $result_code, $result_msg);
    }
    /**
     * @xk 导出其他收益
     * @method  exportOtherMoney
     * @param   BackMoneyModel $backMoneyModel  [description]
     * @return  [type] [description]
     * @Version V5.0
     * @Time    2021-11-11
     * @City    青岛
     * @Author  xkyinzhe <zhonghuaxinxing@sina.cn>
     */
    public function exportOtherMoney(BackMoneyModel $backMoneyModel)
    {
        $param = request()->param();
        $keywords = isset($param['keywords']) ? $param['keywords'] : '';
        $is_finance = isset($param['is_finance']) ? $param['is_finance'] : '';
        $create_time = isset($param['create_time']) ? $param['create_time'] : '';
        $finance_time = isset($param['finance_time']) ? $param['finance_time'] : '';
        $condition = [];
        if ($keywords != '') {
            $condition[] = ['bc.user_sn|bc.sub_order_sn','like','%'.$keywords.'%'];
        }
        if ($is_finance != '') {
            $condition[] = ['bc.is_finance','in',$is_finance];
        }
        if ($create_time != '') {
            $search_time_arr = explode('~', $create_time);
            $start_time = $search_time_arr[0];
            $end_time = $search_time_arr[1];
            // $start_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[0]).' 00:00:00')); //当前时间0点开始
            // $end_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[1]).' 23:59:59')); //当前时间0点开始
            $condition[] = ['bc.create_time', 'between time', $start_time.','.$end_time];
        }
        if ($finance_time != '') {
            $search_time_arr = explode('~', $finance_time);
            $start_time = $search_time_arr[0];
            $end_time = $search_time_arr[1];
            // $start_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[0]).' 00:00:00')); //当前时间0点开始
            // $end_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[1]).' 23:59:59')); //当前时间0点开始
            $condition[] = ['bc.finance_time', 'between time', $start_time.','.$end_time];
        }
        $condition[] = ['act','=','10'];
        $allCount = $backMoneyModel
                   ->alias('bc')
                   ->where($condition)
                   ->count();
        $limit = 10000;
        $pages = ceil($allCount / $limit);
        for ($i = 1; $i <= $pages; ++$i) {
            $data = $backMoneyModel
              ->alias('bc')
              ->leftJoin('user u', 'u.user_sn=bc.user_sn')
              ->where($condition)
              ->field('u.`user_name`,u.`user_sn`,bc.`money`,bc.`content`,bc.`is_finance`,bc.`content`,bc.`create_time`,bc.`finance_time`')
              ->withAttr('is_finance', function ($value, $data) {
                  return $value==0 ? '未出账' : ($value==1 ? '出账成功' : '出账失败');
              })
              ->page($i, $limit)
              ->order('bc.create_time desc')
              ->select()
              ->toArray();
            if ($data) {
                $order_data = [];
                foreach ($data as $key => $value) {
                    $arrays = [];
                    if ($value) {
                        $arrays[] = $value['user_name'];
                        $arrays[] = $value['user_sn'];
                        $arrays[] = $value['money'];
                        $arrays[] = $value['content'];
                        $arrays[] = $value['is_finance'];
                        $arrays[] = $value['create_time'];
                        $arrays[] = $value['finance_time'];
                    }
                    $order_data[] = $arrays;
                }
                $title = ['昵称','用户编号','出账金额','备注','是否出账','创建时间','出账时间'];
                $width = [25,25,20,60,20,25,25];
                $path = '/export/ohterMoney';
                $result = $backMoneyModel->export($title, $order_data, $path, $width, $i, '其他收益表');
                $url_arr[] = $result;
            }
        }
        $code = 200;
        $msg = '请求成功';
        $result_code = 200;
        $result_msg = '导出成功';
        $resultData = $url_arr;
        $this->result($code, $msg, $result_code, $result_msg, $resultData);
    }
    // ****************
    // | 余额转增管理
    // ******************
    /**
     * @xk 余额转赠记录
     *
     * @method balanceTurn
     * @param  MoneyChanageModel $moneyChanageModel         [description]
     * @return [type]            [description]
     * @Time   2021-11-12
     * @City   青岛
     * @Author xkyinzhe          <zhonghuaxinxing@sina.cn>
     */
    public function balanceTurn(MoneyChanageModel $moneyChanageModel)
    {
        $param = request()->param();
        if (request()->isAjax()) {
            $page = isset($param['page']) ? (int)$param['page'] : 1;
            $limit = isset($param['limit']) ? (int)$param['limit'] : 30;
            $push_user_sn = isset($param['push_user_sn']) ? $param['push_user_sn'] : '';
            $user_sn = isset($param['user_sn']) ? $param['user_sn'] : '';
            $max_price = isset($param['max_price']) ? $param['max_price'] : 0.00;
            $min_price = isset($param['min_price']) ? $param['min_price'] : 0.00;
            $status = isset($param['status']) ? $param['status'] : '';
            $search_time = isset($param['search_time']) ? $param['search_time'] : '';
            $condition = [];
            if ($push_user_sn != '') {
                $condition[] = ['cm.push_user_sn','=',$push_user_sn];
            }
            if ($user_sn != '') {
                $condition[] = ['cm.user_sn','=',$user_sn];
            }
            if ($max_price > 0) {
                $condition[] = ['cm.money','<=',$max_price];
            }
            if ($min_price > 0) {
                $condition[] = ['cm.money','>=',$min_price];
            }
            if ($status != '') {
                $condition[] = ['cm.status','in',$status];
            }
            if ($search_time != '') {
                $search_time_arr = explode('~', $search_time);
                $start_time = $search_time_arr[0];
                $end_time = $search_time_arr[1];
                // $start_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[0]).' 00:00:00')); //当前时间0点开始
                // $end_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[1]).' 23:59:59')); //当前时间0点开始
                $condition[] = ['cm.create_time', 'between time', $start_time.','.$end_time];
            }
            $resultData = [];
            $resultData['count'] = $moneyChanageModel->alias('cm')->where($condition)->count();
            $resultData['list'] = $moneyChanageModel
                              ->alias('cm')
                              ->leftJoin('user u', 'u.user_sn=cm.user_sn')
                              ->leftJoin('user pu', 'pu.user_sn=cm.push_user_sn')
                              ->where($condition)
                              ->field('cm.`money_chanage_id`,cm.`push_user_sn`,pu.`user_name` as push_user_name,cm.`user_sn`,u.`user_name`,cm.`money`,cm.`create_time`,cm.`status`,cm.`chanage_money`')
                              ->withAttr('status', function ($value, $data) {
                                  return $value==0 ? '等待处理' : ($value==1 ? '<span style="color:green">审核通过</span>' : '<span style="color:red">审核拒绝</span>');
                              })
                              ->page($page, $limit)
                              ->order('cm.create_time desc')
                              ->select()
                              ->toArray();
            $all_check = $moneyChanageModel
                          ->alias('cm')
                         ->where($condition)
                         ->where([['cm.status','=',1]])
                         ->sum('money');
            $all_back = $moneyChanageModel
                          ->alias('cm')
                        ->where($condition)
                        ->where([['cm.status','=',2]])
                        ->sum('money');
            $all_wait = $moneyChanageModel
                          ->alias('cm')
                          ->where($condition)
                          ->where([['cm.status','=',0]])
                          ->sum('money');
            $resultData['show_count'] = '全部待处理：'.$all_wait.'元;  全部审核成功：'.$all_check.'元； 全部审核驳回：'.$all_back.'元';
            $this->result(200, '请求成功', 200, '加载成功', $resultData);
        }
        return View::fetch();
    }
    /**
     * @xk 执行余额转赠审核
     *
     * @method doBalanceFinance
     * @param  MoneyChanageModel $moneyChanageModel         [description]
     * @param  UserServices      $userServices              [description]
     * @return [type]            [description]
     * @Time   2021-11-12
     * @City   青岛
     * @Author xkyinzhe          <zhonghuaxinxing@sina.cn>
     */
    public function doBalanceFinance(MoneyChanageModel $moneyChanageModel, UserServices $userServices)
    {
        Db::startTrans();
        $code = 200;
        $msg = '请求成功';
        $resultData = [];
        try {
            $param = request()->param();
            $id_str = isset($param['id_str']) ? $param['id_str'] : '';
            $status = isset($param['status']) ? $param['status'] : 1;
            $content = isset($param['content']) ? $param['content'] : '后台审核驳回';
            if ($id_str == '') {
                throw new \think\Exception("请选择需要审核的数据", 404);
            }
            $userServices->syncBalanceFinance($id_str, $status, $content);
            Db::commit();
            $result_code = 200;
            $result_msg = '处理成功';
        } catch (\Exception $e) {
            Db::rollback();
            $result_code = 404;
            $result_msg = $e->getMessage();
        }
        $this->result($code, $msg, $result_code, $result_msg);
    }
    /**
     * @xk 导出余额转赠记录
     *
     * @method exportBalanceTurn
     * @param  MoneyChanageModel $moneyChanageModel         [description]
     * @return [type]            [description]
     * @Time   2021-11-12
     * @City   青岛
     * @Author xkyinzhe          <zhonghuaxinxing@sina.cn>
     */
    public function exportBalanceTurn(MoneyChanageModel $moneyChanageModel)
    {
        $param = request()->param();
        $push_user_sn = isset($param['push_user_sn']) ? $param['push_user_sn'] : '';
        $user_sn = isset($param['user_sn']) ? $param['user_sn'] : '';
        $max_price = isset($param['max_price']) ? $param['max_price'] : 0.00;
        $min_price = isset($param['min_price']) ? $param['min_price'] : 0.00;
        $status = isset($param['status']) ? $param['status'] : '';
        $search_time = isset($param['search_time']) ? $param['search_time'] : '';
        $condition = [];
        if ($push_user_sn != '') {
            $condition[] = ['cm.push_user_sn','=',$push_user_sn];
        }
        if ($user_sn != '') {
            $condition[] = ['cm.user_sn','=',$user_sn];
        }
        if ($max_price > 0) {
            $condition[] = ['cm.money','<=',$max_price];
        }
        if ($min_price > 0) {
            $condition[] = ['cm.money','>=',$min_price];
        }
        if ($status != '') {
            $condition[] = ['cm.status','in',$status];
        }
        if ($search_time != '') {
            $search_time_arr = explode('~', $search_time);
            $start_time = $search_time_arr[0];
            $end_time = $search_time_arr[1];
            // $start_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[0]).' 00:00:00')); //当前时间0点开始
            // $end_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[1]).' 23:59:59')); //当前时间0点开始
            $condition[] = ['cm.create_time', 'between time', $start_time.','.$end_time];
        }
        $allCount = $moneyChanageModel
                    ->alias('cm')
                    ->where($condition)
                    ->count();
        $limit = 10000;
        $pages = ceil($allCount / $limit);
        for ($i = 1; $i <= $pages; ++$i) {
            $data = $moneyChanageModel
              ->alias('cm')
              ->leftJoin('user u', 'u.user_sn=cm.user_sn')
              ->leftJoin('user pu', 'pu.user_sn=cm.push_user_sn')
              ->where($condition)
              ->field('cm.`money_chanage_id`,cm.`push_user_sn`,pu.`user_name` as push_user_name,cm.`user_sn`,u.`user_name`,cm.`money`,cm.`create_time`,cm.`status`')
              ->withAttr('status', function ($value, $data) {
                  return $value==0 ? '等待处理' : ($value==1 ? '审核通过' : '审核拒绝');
              })
              ->page($i, $limit)
              ->order('cm.create_time desc')
              ->select()
              ->toArray();
            if ($data) {
                $order_data = [];
                foreach ($data as $key => $value) {
                    $arrays = [];
                    if ($value) {
                        $arrays[] = $value['push_user_sn'];
                        $arrays[] = $value['push_user_name'];
                        $arrays[] = $value['user_sn'];
                        $arrays[] = $value['user_name'];
                        $arrays[] = $value['money'];
                        $arrays[] = $value['create_time'];
                    }
                    $order_data[] = $arrays;
                }
                $title = ['转出会员号','转出会员昵称','接收会员号','接收会员昵称','交易金额','创建时间'];
                $width = [25,25,25,25,20,25,15];
                $path = '/export/balanceTurn';
                $result = $moneyChanageModel->export($title, $order_data, $path, $width, $i, '余额转增记录表');
                $url_arr[] = $result;
            }
        }
        $code = 200;
        $msg = '请求成功';
        $result_code = 200;
        $result_msg = '导出成功';
        $resultData = $url_arr;
        $this->result($code, $msg, $result_code, $result_msg, $resultData);
    }
    // ****************
    // | 提现审核
    // *******************
    /**
     * @xk 提现审核列表
     *
     * @method withDrawalCheck
     * @param  WithDrawalModel $withDrawalModel           [description]
     * @return [type]          [description]
     * @Time   2021-11-12
     * @City   青岛
     * @Author xkyinzhe        <zhonghuaxinxing@sina.cn>
     */
    public function withDrawalCheck(WithDrawalModel $withDrawalModel)
    {
        $param = request()->param();
        if (request()->isAjax()) {
            $page = isset($param['page']) ? (int)$param['page'] : 1;
            $limit = isset($param['limit']) ? (int)$param['limit'] : 30;
            $keywords = isset($param['keywords']) ? $param['keywords'] : '';
            $search_time = isset($param['search_time']) ? $param['search_time'] : '';
            $status = isset($param['status']) ? $param['status'] : '';
            $condition = [];
            if ($keywords != '') {
                $condition[] = ['w.user_sn|w.name|w.card_num|w.bank_num|u.user_name|w.order_sn|w.name|w.bank_name','like','%'.$keywords.'%'];
            }
            if ($search_time != '') {
                $search_time_arr = explode('~', $search_time);
                $start_time = $search_time_arr[0];
                $end_time = $search_time_arr[1];
                // $start_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[0]).' 00:00:00')); //当前时间0点开始
                // $end_time = date('Y-m-d H:i:s', strtotime(trim($search_time_arr[1]).' 23:59:59')); //当前时间0点开始
                $condition[] = ['w.create_time', 'between time', $start_time.','.$end_time];
            }
            if ($status != '') {
                $condition[] = ['w.status','in',$status];
            }
            // $condition[] = ['w.status','<>',3]; // 未打款完成
            $resultData = [];
            $resultData['list'] = $withDrawalModel
                                      ->alias('w')
                                      ->leftJoin('user u', 'u.user_sn=w.user_sn')
                                      ->where($condition)
                                      ->field('w.`with_drawal_id`,w.`user_sn`,u.`user_name`,w.`bank_num`,w.`money`,w.`status`,w.`status` as status_txt,w.`card_num`,w.`name`,w.`bank_name`,w.`check_time`,w.`next_check_time`,w.`create_time`,w.`order_sn`')
                                      ->withAttr('status_txt', function ($value, $data) {
                                          switch ($value) {
                                          case '0':
                                            return  '等待审核';
                                            break;
                                          case '1':
                                            return '平台确认';
                                            break;
                                          case '2':
                                            return '平台驳回';
                                            break;
                                          case '3':
                                            return '三方打款成功';
                                            break;
                                          case '4':
                                            return '三方打款失败';
                                            break;
                                          default:
                                            return '未知状态';
                                            break;
                                        }
                                      })
                                      ->page($page, $limit)
                                      ->order('w.create_time desc')
                                      ->select()
                                      ->toArray();
            $resultData['count'] = $withDrawalModel
                                      ->alias('w')
                                      ->leftJoin('user u', 'u.user_sn=w.user_sn')
                                      ->where($condition)
                                      ->count();
            $all_push = $withDrawalModel
                        ->alias('w')
                        ->leftJoin('user u', 'u.user_sn=w.user_sn')
                        ->where($condition)
                        ->sum('money');

            $resultData['show_count'] = '合计：'.$all_push.'元;';
            $this->result(200, '请求成功', 200, '加载成功', $resultData);
        }
        return View::fetch();
    }
    /**
     * @xk 执行平台审核
     *
     * @method withDrawalCheckSave
     * @param  WithDrawalModel     $withDrawalCheck           [description]
     * @param  Huigongbao          $huigongbao                [description]
     * @return [type]              [description]
     * @Time   2021-11-12
     * @City   青岛
     * @Author xkyinzhe            <zhonghuaxinxing@sina.cn>
     */
    public function withDrawalCheckSave(WithDrawalModel $withDrawalModel, Huigongbao $huigongbao, UserServices $userServices)
    {
        Db::startTrans();
        $code = 200;
        $msg = '请求成功';
        $resultData = [];
        try {
            $param = request()->param();
            $id_str = isset($param['id_str']) ? $param['id_str'] : '';
            $status = isset($param['status']) ? $param['status'] : '';
            $order_sn = $withDrawalModel->getCodeNo(date('YmdHis'), 15, 1, 'order_sn');
            if ($id_str == '') {
                throw new \think\Exception("请选择需要审核的提现记录", 404);
            }
            switch ($status) {
              case '1':
                $list = $withDrawalModel->where([['with_drawal_id','in',$id_str],['status','=',0]])->field('`with_drawal_id`,`name`,`card_num`,`bank_num`,`money`,`create_time`')->select()->toArray();
                $huigong_data = [];
                $huigong_data['customizableId'] = $order_sn;
                if ($list) {
                    foreach ($list as $key => $value) {
                        $with_data= [];
                        $with_data['order_sn'] = $order_sn;
                        $with_data['withdrawal_sn'] = $withDrawalModel
                                                ->getCodeNo(date('YmdHis').$key, 15, 1, 'withdrawal_sn');
                        $with_data['status'] = 1;
                        $with_data['check_time'] = date('Y-m-d H:i:s');
                        $withDrawalModel->find($value['with_drawal_id'])->save($with_data);
                        $data = [];
                        $data['customizableOrderId'] = $with_data['withdrawal_sn'];
                        $data['account'] = $huigongbao->getBankNum($value['card_num']);
                        $data['name'] = $value['name'];
                        $data['idCard'] = $value['card_num'];
                        $data['payment'] = $value['money'];
                        $huigong_data['statementDetailList'][] = $data;
                    }
                    $res = $huigongbao->syncOrder($huigong_data); // 提交惠工宝
                }
                $result_msg = '处理成功，等待三方打款';
                break;
              case '3':
                $list = $withDrawalModel
                        ->where([['with_drawal_id','in',$id_str],['status','=',0]])
                        ->field('`with_drawal_id`,`name`,`card_num`,`bank_num`,`money`,`create_time`')
                        ->select()
                        ->toArray();
                if ($list) {
                    foreach ($list as $key => $value) {
                        $with_data= [];
                        $with_data['order_sn'] = $order_sn;
                        $with_data['withdrawal_sn'] = $withDrawalModel->getCodeNo(date('YmdHis').$key, 15, 1, 'withdrawal_sn');
                        $with_data['status'] = 3;
                        $with_data['check_time'] = date('Y-m-d H:i:s');
                        $with_data['over_time'] = date('Y-m-d H:i:s');
                        $withDrawalModel->find($value['with_drawal_id'])->save($with_data);
                        $userServices->syncPushSuccess($with_data['withdrawal_sn']); // 记录提现成功
                    }
                }
                $result_msg = '打款成功';
                break;
              case '2':
                $res = $withDrawalModel->where([['with_drawal_id','in',$id_str],['status','=',0]])->save(['status'=>2,'check_time'=>date('Y-m-d H:i:s')]);
                $userServices->syncBackWithDrawal($id_str, 2);
                $result_msg = '处理成功';
                break;
            }
            Db::commit();
            $result_code = 200;
        } catch (\Exception $e) {
            Db::rollback();
            $result_code = 404;
            $result_msg = $e->getMessage();
        }
        $this->result($code, $msg, $result_code, $result_msg, $resultData);
    }
    /**
     * @xk 导出提现记录
     * @method                                      exportWithDrawal
     * @param                                       WithDrawalModel $withDrawalModel  [description]
     * @return                                      [type] [description]
     * @Version：V5.0
     * @Author：xkyinzhe                             <zhonghuaxinxing@sina.cn>
     * @City：青岛
     * @Time：2022-06-07Tfalse13:false32:false24+080
     */
    public function exportWithDrawal(WithDrawalModel $withDrawalModel)
    {
        $param = request()->param();
        $keywords = isset($param['keywords']) ? $param['keywords'] : '';
        $search_time = isset($param['search_time']) ? $param['search_time'] : '';
        $status = isset($param['status']) ? $param['status'] : '';
        $condition = [];
        if ($keywords != '') {
            $condition[] = ['w.user_sn|w.name|w.bank_num|u.user_name','like','%'.$keywords.'%'];
        }
        if ($search_time != '') {
            $search_time_arr = explode('~', $search_time);
            $start_time = $search_time_arr[0];
            $end_time = $search_time_arr[1];
            $condition[] = ['w.create_time', 'between time', $start_time.','.$end_time];
        }
        if ($status != '') {
            $condition[] = ['w.status','in',$status];
        }
        $allCount = $withDrawalModel
                    ->alias('w')
                    ->leftJoin('user u', 'u.user_sn=w.user_sn')
                    ->where($condition)
                    ->count();
        $limit = 10000;
        $pages = ceil($allCount / $limit);
        $url_arr = [];
        for ($i = 1; $i <= $pages; ++$i) {
            $data = $withDrawalModel
                    ->alias('w')
                    ->leftJoin('user u', 'u.user_sn=w.user_sn')
                    ->where($condition)
                    ->field('w.`with_drawal_id`,w.`user_sn`,u.`user_name`,w.`bank_num`,w.`money`,w.`status`,w.`status` as status_txt,w.`card_num`,w.`name`,w.`bank_name`,w.`check_time`,w.`next_check_time`,w.`create_time`,w.`order_sn`')
                    ->withAttr('status_txt', function ($value, $data) {
                        switch ($value) {
                        case '0':
                          return  '等待审核';
                          break;
                        case '1':
                          return '平台确认';
                          break;
                        case '2':
                          return '平台驳回';
                          break;
                        case '3':
                          return '打款成功';
                          break;
                        case '4':
                          return '打款失败';
                          break;
                        default:
                          return '未知状态';
                          break;
                      }
                    })
                    ->page($i, $limit)
                    ->order('create_time desc')
                    ->select()
                    ->toArray();
            if ($data) {
                $order_data = [];
                foreach ($data as $key => $value) {
                    $arrays = [];
                    if ($value) {
                        $arrays[] = $value['user_name'];
                        $arrays[] = $value['user_sn'];
                        $arrays[] = $value['order_sn'];
                        $arrays[] = $value['money'];
                        $arrays[] = $value['card_num']."\t";
                        $arrays[] = $value['name'];
                        $arrays[] = $value['bank_name'];
                        $arrays[] = $value['bank_num']."\t";
                        $arrays[] = $value['status_txt'];
                        $arrays[] = $value['create_time'];
                        $arrays[] = $value['check_time'];
                    }
                    $order_data[] = $arrays;
                }
                $title = ['会员昵称','会员编号','订单编号','申请金额','身份证号码','开户人','开户行','银行卡','审核状态','创建时间','平台审核时间'];
                $width = [25,25,30,20,25,20,25,30,20,25,25];
                $path = '/export/withdrawal';
                $result = $withDrawalModel->export($title, $order_data, $path, $width, $i, '提现记录');
                $url_arr[] = $result;
            }
        }
        $code = 200;
        $msg = '请求成功';
        $result_code = 200;
        $result_msg = '导出成功';
        $resultData = $url_arr;
        $this->result($code, $msg, $result_code, $result_msg, $resultData);
    }
}
